﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Lexware.Tools.ProjectPropertyOverview
{
    public partial class OptionsControl : UserControl
    {
        IDictionary<string, DefaultConfigurationPropertyItem> defaultConfigurationProperties = 
            ProjectProjectConfigurationConstants.PredefinedConfigurationPropertiesAsDict;

        public OptionsControl()
        {
            InitializeComponent();
        }

        public ToolOptions optionsPage;

        // get last settings
        public void Initialize()
        {
            warningLevel.SelectedItem = optionsPage.WarningLevel;
            platformTarget.SelectedItem = optionsPage.PlatformTarget;
            treatWarningAsErrors.Checked = optionsPage.TreatWarningsAsErrors;
            runCodeAnalysis.Checked = optionsPage.RunCodeAnalysis;
        }


        # region Methods
        private void TreatWarningAsErrorsCheckStateChanged(object sender, EventArgs e)
        {
            defaultConfigurationProperties[ProjectProjectConfigurationConstants.TreatwarningsAsErrors].Value = 
                treatWarningAsErrors.Checked;
            optionsPage.TreatWarningsAsErrors = treatWarningAsErrors.Checked;
        }

        private void WarningLevelSelectedIndexChanged(object sender, EventArgs e)
        {
            defaultConfigurationProperties[ProjectProjectConfigurationConstants.WarningLevel].Value = 
                warningLevel.SelectedIndex+1;
            optionsPage.WarningLevel = warningLevel.SelectedItem.ToString();
        }

        private void PlatformTargetSelectedIndexChanged(object sender, EventArgs e)
        {
            defaultConfigurationProperties[ProjectProjectConfigurationConstants.PlatformTarget].Value = 
                platformTarget.SelectedItem;
            optionsPage.PlatformTarget = platformTarget.SelectedItem.ToString();
        }

        private void RunCodeAnalysisCheckedChanged(object sender, EventArgs e)
        {
            defaultConfigurationProperties[ProjectProjectConfigurationConstants.RunCodeAnalysis].Value =
                runCodeAnalysis.Checked;
            optionsPage.RunCodeAnalysis = runCodeAnalysis.Checked;
        }
        # endregion
    }
}
